package com.itlong.cloud.rabbitmq.config;

import com.itlong.cloud.constants.RabbitMQConstant;
import com.itlong.cloud.utils.rabbitMQ.BaseConfig;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
* <desc>
*    项目服务消息队列配置.
* </desc>
*
* @createDate 2017-10-25
*/
@Configuration
public class RabbitConfig extends BaseConfig {


    //声明交互器
    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange(RabbitMQConstant.RABBITMQ_PROJECT_EXCHANGE);
    }
    //删除单元信息的业务队列
    @Bean
    public Queue projectDeleteUnitQueue() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_PROJECT_REMOVE_UNIT_QUEUE,true, false, false, map);
        return queue;
    }

    //删除楼栋信息的业务队列
    @Bean
    public Queue projectDeleteBuildQueue() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_PROJECT_REMOVE_BUILD_QUEUE,true, false, false, map);
        return queue;
    }

    // 修改项目地址业务队列
    @Bean
    public Queue projectUpdateProjectAddressQueue(){
        Map<String,Object> map = new HashMap<>();
        map.put("x-message-ttl",RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange",RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key",RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_PROJECT_UPDATE_PROJECT_ADDRESS_QUEUE,true,false,false,map);
        return queue;
    }

    // 保存月卡缴费记录队列
    @Bean
    public Queue saveMonthCardFeeRecordQueue() {
        Map<String, Object> map = new HashMap<>();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.SAVE_MONTH_CARD_FEE_RECORD_QUEUE,true, false, false, map);
        return queue;
    }

    // 临时停车到账业务队列
    @Bean
    public Queue parkingBillPayQueue(){
        Map<String,Object> map = new HashMap<>();
        map.put("x-message-ttl",RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange",RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key",RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_PARKING_BILL_PEY_MANAGER_QUEUE,true,false,false,map);
        return queue;
    }


    //绑定删除单元业务的队列和路由Key
    @Bean
    Binding deleteUnitBinding() {
        return BindingBuilder.bind(projectDeleteUnitQueue()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_PROJECT_REMOVE_UNIT_INFO_ROUTING_KEY);
    }


    //绑定删除楼栋业务的队列和路由Key
    @Bean
    Binding deleteBuildBinding() {
        return BindingBuilder.bind(projectDeleteBuildQueue()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_PROJECT_REMOVE_BUILD_INFO_ROUTING_KEY);
    }

    // 绑定修改项目地址业务的队列和路由Key
    @Bean
    Binding updateProjectAddressBinding(){
        return BindingBuilder.bind(projectUpdateProjectAddressQueue()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_PROJECT_UPDATE_PROJECT_ADDRESS_ROUTING_KEY);
    }

    // 保存月卡缴费记录队列路由key
    @Bean
    Binding saveMonthCardFeeRecordQueueBinding() {
        return BindingBuilder.bind(saveMonthCardFeeRecordQueue()).to(topicExchange()).with(RabbitMQConstant.SAVE_MONTH_CARD_FEE_RECORD_KEY);
    }

    // 临时停车到账业务的队列和路由Key
    @Bean
    Binding parkingBillPayBinding(){
        return BindingBuilder.bind(parkingBillPayQueue()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_PARKING_BILL_PEY_ROUTING_KEY);
    }

    public static void main(String[] args) {
    }
}
